CSharpTest.Net
TryUpdate(TKey,TValue,TValue) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.BPlusTree Assembly > CSharpTest.Net.Collections Namespace > BPlusTree<TKey,TValue> Class > TryUpdate Method : TryUpdate(TKey,TValue,TValue) Method

key
The object to use as the key of the element to update.
value
The new value for the key if found.
comparisonValue
The value that is compared to the value of the element with key.

Glossary Item Box

Updates an element with the provided key to the value if it exists.

Syntax

Visual Basic (Declaration) 
Public Overloads Function TryUpdate( _
   ByVal key As TKey, _
   ByVal value As TValue, _
   ByVal comparisonValue As TValue _
) As Boolean
C# 
public bool TryUpdate( 
   TKey key,
   TValue value,
   TValue comparisonValue
)

Parameters

key
The object to use as the key of the element to update.
value
The new value for the key if found.
comparisonValue
The value that is compared to the value of the element with key.

Return Value

Returns true if the key provided was found and updated to the value.

Example

BPlusTree/BPlusTree.Test/BasicTests.cs

C#Copy Code
using (BPlusTree<int, string> data = Create(Options))
{
    Assert.IsTrue(data.TryAdd(1, "a"));
    Assert.IsFalse(data.TryAdd(1, "a"));

    Assert.IsTrue(data.TryUpdate(1, "a"));
    Assert.IsTrue(data.TryUpdate(1, "c"));
    Assert.IsTrue(data.TryUpdate(1, "d", "c"));
    Assert.IsFalse(data.TryUpdate(1, "f", "c"));
    Assert.AreEqual("d", data[1]);
    Assert.IsTrue(data.TryUpdate(1, "a", data[1]));
    Assert.AreEqual("a", data[1]);
    Assert.IsFalse(data.TryUpdate(2, "b"));

    string val;
    Assert.IsTrue(data.TryRemove(1, out val) && val == "a");
    Assert.IsFalse(data.TryRemove(2, out val));
    Assert.AreNotEqual(val, "a");
}
VB.NETCopy Code
Using data As BPlusTree(Of Integer, String) = Create(Options)
    Assert.IsTrue(data.TryAdd(1, "a"))
    Assert.IsFalse(data.TryAdd(1, "a"))

    Assert.IsTrue(data.TryUpdate(1, "a"))
    Assert.IsTrue(data.TryUpdate(1, "c"))
    Assert.IsTrue(data.TryUpdate(1, "d", "c"))
    Assert.IsFalse(data.TryUpdate(1, "f", "c"))
    Assert.AreEqual("d", data(1))
    Assert.IsTrue(data.TryUpdate(1, "a", data(1)))
    Assert.AreEqual("a", data(1))
    Assert.IsFalse(data.TryUpdate(2, "b"))

    Dim val As String
    Assert.IsTrue(data.TryRemove(1, val) AndAlso val = "a")
    Assert.IsFalse(data.TryRemove(2, val))
    Assert.AreNotEqual(val, "a")
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys